package com.crm.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.imageio.plugins.bmp.BMPImageWriteParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.crm.model.pojo.Backmoneyplan;
import com.crm.model.pojo.Customer;
import com.crm.model.pojo.Orderinfo;
import com.crm.services.BackmoneyplanService;
import com.crm.services.ContactServices;
import com.crm.services.CustomerServices;
import com.crm.services.OrderInfoServers;
import com.crm.services.OrderitemsServices;
import com.crm.services.ProductServices;
import com.crm.services.RepairForProduceServices;
import com.crm.services.RepairrecordServices;
import com.crm.services.ReturnMoneyService;
import com.crm.services.UserServices;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/aftersale")
public class RepairForProductController {
	
	
	@Autowired
	RepairForProduceServices repairForProduceServices;
	@Autowired
	RepairrecordServices repairrecordServices;
	@Autowired
	ProductServices productServices;
	@Autowired
	OrderitemsServices orderitemsService;

	
	/**
	 * 跳转编辑维修配件详情页
	 * @return 
	 * @return 
	 * @return
	 */
	@GetMapping("/repairProductItem")
	public ModelAndView orderView(Integer id) {
		ModelAndView mv = new ModelAndView("/aftersale/repairProductItem");
		//查询所有产品
		List<Map<String, String>> productAllPage = orderitemsService.productAllPage();
		//配件表详情相关数据
		List<Map<String, String>> selectByID = repairForProduceServices.selectByID(id);
		System.out.println("selectByID:"+selectByID);
		List<Map<String, String>> selectByRid = repairForProduceServices.selectByRid(id);
		System.out.println("跳转配件详情："+selectByRid);
		mv.addObject("repairProductItem", JSONObject.toJSONString(selectByRid));
		String json = JSONObject.toJSONString(productAllPage);
		String json1 = JSONObject.toJSONString(selectByID);
		System.out.println(json1);
		System.out.println(json);
		mv.addObject("rid", id);
		mv.addObject("repairorderItemView", json1);
		mv.addObject("proAll", json);
		System.out.println("编辑维修配件！");
		return mv;
	}
	
	/**
	 * 保存维修配件详细信息
	 */
	@PostMapping("/saveRepairProductItem")
	@ResponseBody
	public String addorderitemview(@RequestParam("proitem") Object proid,@RequestParam("ID") Integer id) {
		String str= String.valueOf(proid);
		System.out.println(id);
		@SuppressWarnings("unchecked")
		List<Map<String,String>> itemNews = JSONArray.parseObject(str,List.class);
		System.out.println(itemNews+"\n"+id);
		repairForProduceServices.add(itemNews,id);
		return "保存维修配件详细信息";
	}
	
}
